package com.yonyou.gmmc.dealerApp.api.config;

import java.util.Properties;

import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import com.yonyou.gmmc.common.annotation.MySQLDb;
import com.yonyou.gmmc.common.annotation.OracleDb;
import com.yonyou.gmmc.dealerApp.api.constant.DealerAppConstant;

import tk.mybatis.spring.mapper.MapperScannerConfigurer;

@Configuration
//注意，由于MapperScannerConfigurer执行的比较早，所以必须有下面的注解
@AutoConfigureAfter(DatasourceConfig.class)
public class MyBatisMapperScannerConfig {
//	 	@Bean
//	 	@Primary
//	    public MapperScannerConfigurer mapperScannerConfigurer() {
//	 		 MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
//		        mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactoryMySql");
//		        mapperScannerConfigurer.setBasePackage(DealerAppConstant.DAO_PACKAGE);
//		        mapperScannerConfigurer.setAnnotationClass(MySQLDb.class);
//		        Properties properties = new Properties();
//		        properties.setProperty("mappers", DealerAppConstant.UTIL_PACKAGE+".MyMapper");
//		        properties.setProperty("notEmpty", "false");
//		        properties.setProperty("IDENTITY", "MYSQL");
//		        mapperScannerConfigurer.setProperties(properties);
//		        return mapperScannerConfigurer;
//	    }
	 	
	 	@Bean
	    public MapperScannerConfigurer mapperScannerConfigurerOracle() {
	 		 MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
		        mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactoryOracle");
		        mapperScannerConfigurer.setBasePackage(DealerAppConstant.DAO_PACKAGE);
		        mapperScannerConfigurer.setAnnotationClass(OracleDb.class);
		        Properties properties = new Properties();
		        properties.setProperty("mappers", DealerAppConstant.UTIL_PACKAGE+".MyMapper");
		        properties.setProperty("notEmpty", "false");
		        properties.setProperty("IDENTITY", "ORACLE");
		        mapperScannerConfigurer.setProperties(properties);
		        return mapperScannerConfigurer;
	    }
}